//
//  SPNavigationController.m
//  panzer
//
//  Created by 还带大道 on 2018/10/19.
//  Copyright © 2018年 还带大道. All rights reserved.
//

#import "SPNavigationController.h"
#import "SPCommon.h"

@interface SPNavigationController ()

@end

@implementation SPNavigationController

//第一次使用这个类的时候会调用一次
+(void)initialize
{
    //初始化一些属性
    UINavigationBar *navBar = [UINavigationBar appearance];
    
    //设置背景(会默认navBar.translucent = NO 即关闭半透明属性view.y=64,高度不变)
    //    [navBar setBackgroundImage:[UIImage imageNamed:@"ic_nav"] forBarMetrics:UIBarMetricsDefault];
    //设置导航条颜色
    navBar.barTintColor = [UIColor whiteColor];
    // 设置返回按钮的颜色
    //    navBar.tintColor = [UIColor whiteColor];
    
    
    //设置标题颜色及大小
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = RZ_COLOR(74, 74, 74);
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:18];
    [navBar setTitleTextAttributes:attrs];
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationBar];
}


//找出导航栏底部横线
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //push的时候隐藏底部条
    if(self.viewControllers.count > 0){
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
    
}


@end
